<template>
  <layout class="no-padding h-75vh">
    <template slot="search">
      <!-- 面包屑 -->
      <div class="breadcrumb">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item>工艺工时设计</el-breadcrumb-item>
          <el-breadcrumb-item>返修处理</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <el-form inline :model="repairSearchParams">
        <div class="search-left">
          <el-form-item>
            <el-input v-model="repairSearchParams.dispatchFormNumber" class="w150" placeholder="派工单号" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="repairSearchParams.processName" class="w150" placeholder="返修工序" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-select v-model="repairSearchParams.state" class="w150" placeholder="生产状态" clearable filterable>
              <template v-for="item in stateList">
                <el-option :label="item" :value="item" :key="item"></el-option>
              </template>
            </el-select>
          </el-form-item>
          <el-button @click="clear()">重置</el-button>
          <el-button type="primary" @click="repairSearch()">查询</el-button>
        </div>
      </el-form>
    </template>
    <template slot="content">
      <el-table border stripe :data="thirdData" row-key="id" @row-dblclick="showProcessDetail">
        <el-table-column type="index" label="序号" align="center" width="60"></el-table-column>
        <el-table-column prop="dispatchFormNumber" sortable label="派工单号" align="center" width="150"></el-table-column>
        <el-table-column prop="processName" label="返修工序" align="center" width="120"></el-table-column>
        <el-table-column prop="number" label="返修数量" align="center" width="120"></el-table-column>
        <el-table-column prop="drawingNumber" label="图号" align="center" width="150"></el-table-column>
        <el-table-column prop="productName" label="品名" align="center" width="150"></el-table-column>
        <el-table-column prop="materialQuality" label="材质" align="center" width="150"></el-table-column>
        <el-table-column prop="producingState" label="状态" align="center" width="120"></el-table-column>
        <el-table-column prop="remark" label="备注" align="center" min-width="120"></el-table-column>
        <el-table-column prop="state" label="设计工艺表" align="left" fixed="right" width="120" v-if="$checkAuth('工艺路线投产提交')">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" @click="onClickDesign(scope.row, '返修品')" :disabled="!canDesignState.includes(scope.row.producingState)">设计</el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </layout>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { namespace } from 'vuex-class'
import Layout from '@/views/_common/Layout.vue'
import _ from 'lodash'

const vuexProcess = namespace('TwoProcess')
const vuexEnter = namespace('TwoEnter')

@Component({
  components: {
    Layout
  }
})
export default class Index extends Vue {
  @vuexProcess.State productOnDesignVersion: any
  @vuexEnter.State thirdData: any
  @vuexEnter.Action GET_REWORK_LIST: any

  stateList: String[] = ['工艺设计', '工艺审批', '待派工', '生产中', '已完成', '生产通知变更', '工艺变更设计', '工艺变更审批']
  canDesignState: any[] = ['工艺设计', '待派工', '生产中', '工艺设计变更'] // 可以变更设计的产品状态

  repairSearchParams: any = {
    dispatchFormNumber: '',
    processName: '',
    state: '',
    page: 1,
    pageSize: 20
  }

  /**
   * 生命周期函数 返修列表查询
   */
  created() {
    this.GET_REWORK_LIST({ ...this.repairSearchParams })
  }

  /**
   * 条件查询返修记录
   */
  repairSearch() {
    this.GET_REWORK_LIST({ ...this.repairSearchParams })
  }

  /**
   * 清空查询条件（初始化）
   */
  clear() {
    // 返修处理
    this.repairSearchParams = {
      dispatchFormNumber: '',
      processName: '',
      state: '',
      page: 1,
      pageSize: 20
    }
    this.repairSearch()
  }

  /**
   * 双击查看设计详情
   */
  showProcessDetail(row) {
    this.onClickDesign(row, '返修工艺详情')
  }

  /**
   * 点击设计按钮进入设计页面
   */
  onClickDesign(product, type) {
    let tempProduct = {
      producingId: product.producingId,
      drawingNumber: product.drawingNumber,
      productName: product.productName,
      materialQuality: product.materialQuality,
      number: product.number
    }
    this.$store.commit('TwoProcess/SET_PRODUCT_ON_DESIGN_VERSION', tempProduct)
    this.$router.push({ name: 'design', params: { type } })
  }
}
</script>

<style lang="scss" scoped>
.total {
  float: left;
  // display: inline;
  border: 1px solid #ccc;
  margin-right: 30px;
  .total_title {
    width: 200px;
    color: #000;
    height: 260px;
    line-height: 30px;
    text-align: center;
    .text {
      font-size: 18px;
      font-weight: bold;
      margin: 0 5px;
    }
  }

  &:hover {
    color: #000;
    background: #fff;
  }
}
.s1 {
  display: none;
}
.s2 {
  height: 100px;
  display: none;
}

//通知单滚动
.notice-box {
  display: -webkit-box;
  overflow-x: auto;
  /*适应苹果*/
  -webkit-overflow-scrolling: touch;
}
.breadcrumb {
  height: 25px;
  width: 100%;
  border: none;
}
.notice-item {
  height: 270px;
}

/*隐藏掉滚动条*/
.notice-box::-webkit-scrollbar {
  display: none;
}

.layout .operation {
  overflow-x: auto;
}
.el-tabs {
  padding: 0 20px;
  margin: 0px 10px 0;
  border: 1px solid #e4e7ed;
  background-color: #fff;
  .el-tabs__content {
    min-width: 1200px;
  }
}
</style>